package com.chatsimple.netty

import com.ly.data.MessageProtobuf.TaskProto
import io.netty.buffer.ByteBuf
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.MessageToByteEncoder

class TaskEncoder : MessageToByteEncoder<TaskProto>() {
    override fun encode(ch: ChannelHandlerContext?, task: TaskProto?, byteBuf: ByteBuf?) {
        task ?: return
        byteBuf ?: return
        val contentArray = task.toByteArray()
        val length = contentArray.size
        byteBuf.writeIntLE(length)
        byteBuf.writeBytes(contentArray)
    }
}